export function host(url) {
  const host = url.replace(/^https?:\/\//, '').replace(/\/.*$/, '');
  const parts = host.split('.').slice(-3);
  if (parts[0] === 'www') parts.shift();
  return parts.join('.');
}

export function voteTime(time) {
  const d = new Date(time * 1000);
  const nowYear = new Date().getFullYear();
  let nowMonth = new Date().getFullYear() + 1;
  let nowDay = new Date().getFullYear();
  const year = d.getFullYear();
  let month = d.getMonth() + 1;
  let date = d.getDate();
  let hour = d.getHours();
  let minute = d.getMinutes();
  if (nowMonth < 10) {
    nowMonth = '0' + nowMonth;
  }
  if (nowDay < 10) {
    nowDay = '0' + nowDay;
  }
  if (month < 10) {
    month = '0' + month;
  }
  if (date < 10) {
    date = '0' + date;
  }
  if (hour < 10) {
    hour = '0' + hour;
  }
  if (minute < 10) {
    minute = '0' + minute;
  }
  if (nowYear === year) {
    if (nowMonth === month && nowDay === date) {
      return '今天 ' + hour + ':' + minute;
    } else if (nowMonth !== month || nowDay !== date) {
      return month + '-' + date + ' ' + hour + ':' + minute;
    }
  }
  return year + '-' + month + '-' + date + ' ' + hour + ':' + minute;
}
